﻿$(window).load(function () {
	if ($('#kpilistpage_splitter').length > 0) {
		var h = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) - $('.header').height() - $('.footer').height() - 10 - $('.pagetitle').height() - 30;
		var w = $('.main').width();
		if ($('.splitter-panel').length > 1) {
			$('#kpilistpage_splitter').jqxSplitter({ width: w, height: h, resizable: false, panels: [{ size: 245 }, { size: w - 245}] });
			$('#groupnavcontainer').height(h);

			$('.jqx-splitter-collapse-button-vertical').attr('title', '展开/折叠菜单');

			$('#kpilistpage_splitter').on('expanded', function (event) {
				var btn = $('.jqx-splitter-collapse-button-vertical-collapsed');
				btn.removeClass('jqx-splitter-collapse-button-vertical-collapsed');
				btn.addClass('jqx-splitter-collapse-button-vertical');
			});

			$('#kpilistpage_splitter').on('collapsed', function (event) {
				var btn = $('.jqx-splitter-collapse-button-vertical');
				btn.removeClass('jqx-splitter-collapse-button-vertical');
				btn.addClass('jqx-splitter-collapse-button-vertical-collapsed');
			});
		}
		$('#kpilistcontent').height(h);
	}

	if ($('#kpihistoricaldatapage_splitter').length > 0) {
		var h = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) - $('.header').height() - $('.options').height() - $('.footer').height() - 10 - $('.pagetitle').height() - 50;
		var w = $('.main').width();
		if ($('.splitter-panel').length > 1) {
			$('#kpihistoricaldatapage_splitter').jqxSplitter({ width: w, height: h, resizable: false, panels: [{ size: 245 }, { size: w - 245}] });
			$('#groupnavcontainer').height(h);

			$('.jqx-splitter-collapse-button-vertical').attr('title', '展开/折叠菜单');

			$('#kpihistoricaldatapage_splitter').on('expanded', function (event) {
				var btn = $('.jqx-splitter-collapse-button-vertical-collapsed');
				btn.removeClass('jqx-splitter-collapse-button-vertical-collapsed');
				btn.addClass('jqx-splitter-collapse-button-vertical');
			});

			$('#kpihistoricaldatapage_splitter').on('collapsed', function (event) {
				var btn = $('.jqx-splitter-collapse-button-vertical');
				btn.removeClass('jqx-splitter-collapse-button-vertical');
				btn.addClass('jqx-splitter-collapse-button-vertical-collapsed');
			});
		}
		$('#kpilistcontent').height(h);
	}
});



function listKPIOperator_Change(sender, kpiid) {
	var selectedItem = $(sender).find("option:selected").text();

	if (selectedItem != "选择操作") {
		if (selectedItem == '修改') {
			window.location.assign('KPIEdit.aspx?kpiid=' + kpiid);
			return;
		}

		if (selectedItem == '删除') {
			if (confirm('确定要删除吗?')) {
				$.ajax({
					type: "POST", url: getKPIOperateSvcURL() + "DeleteKPI", contentType: "application/json; charset=utf-8",
					dataType: "json", data: '{ "id": ' + kpiid + '}', async: false, cache: false,
					success: function (result) {
						if (result) {
							window.location.reload();
						}
						else {
							showError('删除失败,请稍后再试或联系技术人员.');
						}
					},
					error: function () {
						showError('请求失败.');
					}
				});
			}
			else {
				$(sender).val('选择操作');
			}

			return;
		}

		if (selectedItem == '审核通过') {
			if (confirm('确定要通过审核吗?')) {
				$.ajax({
					type: "POST", url: getKPIOperateSvcURL() + "ReviewApproved", contentType: "application/json; charset=utf-8",
					dataType: "json", data: '{ "id": ' + kpiid + '}', async: false, cache: false,
					success: function (result) {
						if (result) {
							window.location.reload();
						}
						else {
							showError('操作失败,请稍后再试或联系技术人员.');
						}
					},
					error: function () {
						showError('请求失败.');
					}
				});
			}
			else {
				$(sender).val('选择操作');
			}

			return;
		}

		if (selectedItem == '审核不通过') {
			if (confirm('确定要不通过审核吗?')) {
				$.ajax({
					type: "POST", url: getKPIOperateSvcURL() + "ReviewNotApproved", contentType: "application/json; charset=utf-8",
					dataType: "json", data: '{ "id": ' + kpiid + '}', async: false, cache: false,
					success: function (result) {
						if (result) {
							window.location.reload();
						}
						else {
							showError('操作失败,请稍后再试或联系技术人员.');
						}
					},
					error: function () {
						showError('请求失败.');
					}
				});
			}
			else {
				$(sender).val('选择操作');
			}

			return;
		}

		if (selectedItem == '申请修改') {
			if (confirm('确定要申请修改吗?')) {
				$.ajax({
					type: "POST", url: getKPIOperateSvcURL() + "KPIModificationRequest", contentType: "application/json; charset=utf-8",
					dataType: "json", data: '{ "id": ' + kpiid + '}', async: false, cache: false,
					success: function (result) {
						if (result) {
							window.location.reload();
						}
						else {
							showError('操作失败,请稍后再试或联系技术人员.');
						}
					},
					error: function () {
						showError('请求失败.');
					}
				});
			}
			else {
				$(sender).val('选择操作');
			}

			return;
		}

		if (selectedItem == '允许修改') {
			if (confirm('确定要允许修改吗?')) {
				$.ajax({
					type: "POST", url: getKPIOperateSvcURL() + "KPIModificationRequestReview", contentType: "application/json; charset=utf-8",
					dataType: "json", data: '{ "id": ' + kpiid + ',"approved": true' + '}', async: false, cache: false,
					success: function (result) {
						if (result) {
							window.location.reload();
						}
						else {
							showError('操作失败,请稍后再试或联系技术人员.');
						}
					},
					error: function () {
						showError('请求失败.');
					}
				});
			}
			else {
				$(sender).val('选择操作');
			}

			return;
		}

		if (selectedItem == '不允许修改') {
			if (confirm('确定要不允许修改吗?')) {
				$.ajax({
					type: "POST", url: getKPIOperateSvcURL() + "KPIModificationRequestReview", contentType: "application/json; charset=utf-8",
					dataType: "json", data: '{ "id": ' + kpiid + ',"approved": false' + '}', async: false, cache: false,
					success: function (result) {
						if (result) {
							window.location.reload();
						}
						else {
							showError('操作失败,请稍后再试或联系技术人员.');
						}
					},
					error: function () {
						showError('请求失败.');
					}
				});
			}
			else {
				$(sender).val('选择操作');
			}

			return;
		}

		if (selectedItem == '审核修改的KPI') {
			window.location.assign('KPIDetail.aspx?kpiid=' + kpiid);

			return;
		}

		if (selectedItem == '进度上报') {
			window.location.assign('ProgressReport.aspx?kpiid=' + kpiid);

			return;
		}

		if (selectedItem == '申请修改进度') {
			if (confirm('确定要申请修改进度吗?')) {
				$.ajax({
					type: "POST", url: getKPIOperateSvcURL() + "KPIProgressModificationRequest", contentType: "application/json; charset=utf-8",
					dataType: "json", data: '{ "id": ' + kpiid + '}', async: false, cache: false,
					success: function (result) {
						if (result) {
							window.location.reload();
						}
						else {
							showError('操作失败,请稍后再试或联系技术人员.');
						}
					},
					error: function () {
						showError('请求失败.');
					}
				});
			}
			else {
				$(sender).val('选择操作');
			}

			return;
		}

		if (selectedItem == '允许修改进度') {
			if (confirm('确定要允许修改进度吗?')) {
				$.ajax({
					type: "POST", url: getKPIOperateSvcURL() + "KPIProgressModificationRequestReview", contentType: "application/json; charset=utf-8",
					dataType: "json", data: '{ "id": ' + kpiid + ',"approved": true' + '}', async: false, cache: false,
					success: function (result) {
						if (result) {
							window.location.reload();
						}
						else {
							showError('操作失败,请稍后再试或联系技术人员.');
						}
					},
					error: function () {
						showError('请求失败.');
					}
				});
			}
			else {
				$(sender).val('选择操作');
			}

			return;
		}

		if (selectedItem == '不允许修改进度') {
			if (confirm('确定要不允许修改进度吗?')) {
				$.ajax({
					type: "POST", url: getKPIOperateSvcURL() + "KPIProgressModificationRequestReview", contentType: "application/json; charset=utf-8",
					dataType: "json", data: '{ "id": ' + kpiid + ',"approved": false' + '}', async: false, cache: false,
					success: function (result) {
						if (result) {
							window.location.reload();
						}
						else {
							showError('操作失败,请稍后再试或联系技术人员.');
						}
					},
					error: function () {
						showError('请求失败.');
					}
				});
			}
			else {
				$(sender).val('选择操作');
			}

			return;
		}

		if (selectedItem == '修改进度') {
			window.location.assign('ProgressEdit.aspx?kpiid=' + kpiid);

			return;
		}

		if (selectedItem == '审核修改的进度') {
			window.location.assign('ProgressDetail.aspx?kpiid=' + kpiid);

			return;
		}

		if (selectedItem == '年底考核') {
			window.location.assign('EndOfTheYearAppraisal.aspx?kpiid=' + kpiid);

			return;
		}

	}
}

function btnExpandKPIProgress_Click(sender, kpiprgresscontainer) {
	if (kpiprgresscontainer) {
		if ($(sender).text() == "显示进度") {
			$(kpiprgresscontainer).slideDown();
			$(sender).text('隐藏进度');
		}
		else {
			$(kpiprgresscontainer).slideUp();
			$(sender).text('显示进度');
		}
	}
}

